<h1>Listing documents</h1>

<table>
  <tr>
    <th>Issue date</th>
	<th>Type</th>
	<th>Number</th>
	<th>Source</th>
	<th>Target</th>
    <th>Notes</th>
    <th>Creator</th>
  </tr>
  
  <tr align="center">
  <% form_tag :action => 'findInteresting' do %>
    <td style="text-align: right">
	from <%= date_select("filter", "issue_date_from", :start_year => 2000, :use_month_numbers => true, :prompt => { :day => 'D', :month => 'M', :year => 'Y' }) %>
	<br/>
	to <%= date_select("filter", "issue_date_to", :start_year => 2000, :use_month_numbers => true, :prompt => { :day => 'D', :month => 'M', :year => 'Y' }) %>
	</td>
	<td><%= select("filter", "type", %w(MM WZ PZ), { :include_blank => true }) %></td>
    <td><%= text_field("filter", "number", :size => 15) %></td>
	<td><%= select("filter", "source", Transactor.find(:all).collect {|t| [ t.name, t.id ] }, { :include_blank => true }) %></td>
	<td><%= select("filter", "target", Transactor.find(:all).collect {|t| [ t.name, t.id ] }, { :include_blank => true }) %></td>
    <td><%= text_field("filter", "notes", :size => 20) %></td>
	<td><%= select("filter", "creator", Employee.find(:all).collect {|t| [ t.name + " " + t.surname, t.id ] }, { :include_blank => true }) %></td>
    <td><input type="submit" value="Filter" /></td>
  <% end %>
  </tr>

<% @documents.each do |document| %>
  <tr>
    <td class="date_cell"><%=h document.issue_date.strftime('%Y-%m-%d') %></td>
	<td><%=h document.document_type %></td>
    <td><%=h document.number %></td>
	<% if document.source %>
	  <td><%= link_to document.source.name, document.source %></td>
	<% end %>
	<% if document.target %>
	  <td><%= link_to document.target.name, document.target %></td>
	<% end %>
    <td><%=h truncate(document.notes, :length => 20) %></td>
    <td><%=h document.employee.name + " " + document.employee.surname%></td>
	<td/>
    <td><%= link_to 'Show', document %></td>
    <td><%= link_to 'Edit', edit_document_path(document) %></td>
    <td><%= link_to 'Delete', document, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'New document', new_document_path %>